<%--
  Created by IntelliJ IDEA.
  User: nieyu
  Date: 2016/9/1
  Time: 10:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>上传学生评教信息</title>
    <script src="<%=request.getContextPath()%>/resources/js/md5.js"></script>
</head>
<body>

<form method="post" action="<%=request.getContextPath()%>/upload/student/upload" enctype="multipart/form-data">
    <input type="file" id="ChooseFile" value="选择文件" name="files"  accept=".xls,.xlsx"/>
    <input type="hidden" id="log" name="md5"/>
    <input type="submit" value="上传文件" onclick="sAlert('文件正在上传...........');">
</form>

</body>
</html>
<script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/prompt.js"></script>
<script>
    var log = document.getElementById("log");
    document.getElementById("ChooseFile").addEventListener("change", function () {
        var blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice,
                file = this.files[0],
                chunkSize = 2097152, // 将文件切割成2m读取 因为文件太大可能读取失败
                chunks = Math.ceil(file.size / chunkSize),
                currentChunk = 0,
                spark = new SparkMD5.ArrayBuffer(),
                frOnload = function (e) {
                    spark.append(e.target.result);
                    currentChunk++;
                    if (currentChunk < chunks)//判断是否读取完成
                        loadNext();
                    else
                        log.value = spark.end().toUpperCase();

                };

        function loadNext() {
            var fileReader = new FileReader();
            fileReader.onload = frOnload;
            var start = currentChunk * chunkSize,
                    end = ((start + chunkSize) >= file.size) ? file.size : start + chunkSize;
            fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
        };
        loadNext();//调用
    });
</script>